<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            收货上架
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">
        <ul class="aui-list aui-form-list">
            <!-- <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">发货单号</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请 扫描/输入 发货单号" id="consignment" value=""
                            onclick="getIdSelector();">
                    </div>
                </div>
            </li> -->
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">仓库</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择/扫描 仓库" id="workCenterCode" value=""
                            onclick="getIdSelector();" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCenter()"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">库位</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择/扫描 库位" id="workCellCode" value=""
                            onclick="getIdSelector();" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCell()"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">箱号</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请扫描箱号" id="boxnum" value="" onclick="getIdSelector();">
                    </div>
                </div>
            </li>
            <!-- <li class="aui-list-item" style="display:none">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="font-size: 14px;">条码</div>
                    <input type="text" class="aui-input" style="width: 80%;font-size: 14px;" id="tm">
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">物料号</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="mrlCode" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">批次号</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="lotCode" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">数量</div>
                    <div class="aui-list-item-input">
                        <input type="number" id="qty">
                    </div>
                </div>
            </li> -->

        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="save()">保存</div>
        <div style="width:100%;margin-top:4%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block"><input type="text" class="aui-input"
                style="width: 80%;font-size: 16px;" id="message" /></div>

        <!-- <div style="background-color:white; height: 100%;width: 100%;margin-top:3%;border:solid 1px #D3D3D3;display:none;margin-bottom:50px;"
            id="details">
            <table class="table" style='width:100%; font-size:14px;' id="boxTable">
                <tbody id="tbodyHtml1">
                </tbody>
            </table>
        </div> -->
        <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;margin-bottom:20%;" id="tbodyHtml">

        </div>
        <div style="background-color:white; height: 100%;width: 100%;margin-top:3%;border:solid 1px #D3D3D3;display:none;margin-bottom:50px;"
            id="tableDiv">
            <table class="table" style='width:100%; font-size:14px;' id="table">
                <tbody>
                    <tr>
                        <td style="width:20%;text-align:right;">入库单号:</td>
                        <td id="inBillCodeT"></td>
                    </tr>

                    <tr>
                        <td style="width:20%;text-align:right;">仓&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp库:</td>
                        <td id="workCenterNameT"></td>
                    </tr>
                    <tr>
                        <td style="width:20%;text-align:right;">库&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp位:</td>
                        <td id="workCellNameT"></td>
                    </tr>
                    <tr>
                        <td style="width:20%;text-align:right;">操&nbsp&nbsp作&nbsp&nbsp者:</td>
                        <td id="createIdT"></td>
                    </tr>
                    <tr>
                        <td style="width:20%;text-align:right;">操作时间:</td>
                        <td id="createDateT"></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var workCenterGid = ""; //仓库GID
    var workCenterCode = ""; //仓库编码
    var workCenterName = ""; //仓库名称
    var workCellGid = ""; //库位GID
    var workCellCode = ""; //库位编码
    var workCellName = ""; //库位名称
    var initWorkCenterId = "";
    var scanRule = ""; //条码解析规则
    var sfkFlag = "N";
    var html = ""; //全局拼接HTML
    // var tbodyHtml1 = ""; //全局拼接TMID  的HTML表格
    var array = new Array();

    var delArray = new Array();
    var flag = true;

    //初始化查询明细数据和下拉框下拉框
    apiready = function () {


        idSelector = "workCellCode";
        api.setFocus({
            inputId: 'workCellCode',
            focus: true
        })

        //查询条码解析规则
        initScanRule();
        //初始化，判断登录用户是不是三方库的，是则默认显示三方库仓库
        initSearch();
    }

    //初始化，判断登录用户是不是三方库的，是则默认显示三方库仓库
    function initSearch() {
        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getInitSHWorkCenter";
        var data = {
            values: {
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {

                    sfkFlag = myobj.sfkFlag;
                    initWorkCenterId = myobj.workCenterId;
                    initWorkCenterCode = myobj.workCenterCode;
                    initWorkCenterName = myobj.workCenterName;

                    //三方库账号
                    if (sfkFlag == "Y") {
                        workCenterGid = initWorkCenterId;
                        workCenterCode = initWorkCenterCode + ":" + initWorkCenterName;
                        workCenterName = initWorkCenterName;
                        document.getElementById("workCenterCode").value = workCenterCode;
                    }
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //查询扫描规则
    function initScanRule() {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem("un");
        var url = serverUrl + "/app/getTmScanRule";
        var data = {
            values: {
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    scanRule = myobj.scanRule
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }


    //1：仓库扫描校验
    function getWorkCenter(code, inputId) {
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkCenter";
        var data = {
            values: {
                workCenterCodeQ: code,
                mrlCode: "",
                lotCode: "",
                qty: ""
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);

                    //三方库账号
                    if (sfkFlag == "Y") {
                        if (list[0].workCenterGid != initWorkCenterId) {
                            api.toast({
                                msg: "扫描的仓库编码【" + list[0].workCenterCode + ":" + list[0].workCenterName + "】不是三方库对应仓库!",
                                duration: 3000
                            });
                            $("#workCenterCode").focus();
                            $("#workCenterCode").select();
                            return;
                        }
                    }
                    workCenterGid = list[0].workCenterGid;
                    workCenterCode = list[0].workCenterCode + ":" + list[0].workCenterName;
                    workCenterName = list[0].workCenterName;
                    document.getElementById(inputId).value = workCenterCode;
                    $("#workCellCode").focus();
                    idSelector = "workCellCode";

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#workCenterCode").focus();
                    $("#workCenterCode").select();
                }
            }
        });
    }

    //1：仓库扫描校验
    function getWorkCenterGid(gid) {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem("un");
        var url = serverUrl + "/app/getWorkCenterGid";
        var data = {
            values: {
                workCellGid: gid,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    workCenterGid = myobj.workCenterGid;
                    workCenterCode = myobj.workCenterCode;
                    workCenterName = myobj.workCenterName;
                    document.getElementById("workCenterCode").value = myobj.workCenterCode + ":" + myobj.workCenterName;
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    idSelector = "boxnum";
                    api.setFocus({
                        inputId: 'boxnum',
                        focus: true
                    })
                    $("#boxnum").select();
                }
            }
        });
    }

    //2：选择仓库
    function goSelectWorkCenter() {
        api.openWin({
            name: 'uwmSelectWorkCenter',
            url: 'uwmSelectWorkCenter.html',
            pageParam: {
                flag: "in",
                name: "uwmYqgyReceipt_boxAnChuang",
                mrlCode: "",
                lotCode: "",
                sfkFlag: sfkFlag,
                workCenterId: initWorkCenterId,
                qty: ""
            }
        });
    }

    //仓库选择后回调函数
    function setWorkCenter(id, code, name) {
        workCenterGid = id;
        workCenterCode = code;
        workCenterName = name;
        //$("#workCenterCode").attr("value",code+":"+name);
        document.getElementById('workCenterCode').value = code + ":" + name;
        $("#workCellCode").focus();
        idSelector = "workCellCode";
    }

    //3；PDA自带扫描回车事件
    $("#workCenterCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            //仓库编码
            $("#workCenterCode").val(sm);
            getWorkCenter(sm, "workCenterCode");
        }
    });

    //5:库位扫描校验
    function getWorkCell(code, inputId) {
        //扫库位前先扫仓库
        /*   if (inputId == "workCellCode") {
              if (workCenterGid == "" || workCenterGid == null || workCenterGid == undefined) {
                  api.toast({
                      msg: "请先选择/扫描 仓库",
                      duration: 3000
                  });
                  $("#workCellCode").val("");
                  workCellCode = "";
                  workCellGid = "";
                  workCellName = "";
                  return;
              }
          } */
        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkCell";
        var data = {
            values: {
                flag: "in_rk",
                workCenterGid: workCenterGid, //仓库GID
                workCellCode: code, //库位编码
                relWorkCellGid: "", //调入库位
                tm: "",
                workCellFlag: "", //原库位调入库位flag
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    workCellGid = list[0].workCellGid;
                    workCellCode = list[0].workCellCode + ":" + list[0].workCellName;
                    workCellName = list[0].workCellName;
                    document.getElementById(inputId).value = workCellCode;
                    getWorkCenterGid(workCellGid)
                    idSelector = "boxnum";
                    api.setFocus({
                        inputId: 'boxnum',
                        focus: true
                    })
                    $("#boxnum").focus();
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#workCellCode").focus();
                    $("#workCellCode").select();
                }
            }
        });
    }

    //6：选择库位
    function goSelectWorkCell() {
        //仓库非空校验
        /*   if (workCenterGid == "" || workCenterGid == null || workCenterGid == undefined) {
              api.toast({
                  msg: "请先选择/扫描 仓库",
                  duration: 3000
              });
              return;
          } */

        api.openWin({
            name: 'uwmSelectWorkCell',
            url: 'uwmSelectWorkCell.html',
            pageParam: {
                flag: "in_rk",
                name: "uwmYqgyReceipt_boxAnChuang",
                tm: "",
                workCenterGid: workCenterGid,
                relWorkCellGid: "",
                workCellFlag: ""
            }
        });
    }

    //库位选择后回调函数
    function setWorkCell(id, code, name) {
        workCellGid = id;
        workCellCode = code;
        workCellName = name;
        document.getElementById('workCellCode').value = code + ":" + name;
        getWorkCenterGid(workCellGid)
        idSelector = "boxnum";
        api.setFocus({
            inputId: 'boxnum',
            focus: true
        })
    }


    //7；PDA自带扫描回车事件-库位
    $("#workCellCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            //仓库编码
            $("#workCellCode").val(sm);
            //校验改箱码是否存在
            getWorkCell(sm, "workCellCode");
        }
    });

    //发货单监听回车事件
    // $("#consignment").on('keypress', function (e) { //#keyword为input文本框
    //     var keycode = e.keyCode;
    //     var consignment = $(this).val();
    //     if (keycode == '13') {
    //         if (consignment != null && consignment != "" && consignment != undefined) {
    //             $("#consignment").blur();
    //             console.log(consignment);


    //             //发货单
    //             $("#consignment").val(consignment);
    //         }


    //     }
    // });

    //箱号监听回车事件
    $("#boxnum").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            if (tm != null && tm != "" && tm != undefined) {
                $("#boxnum").blur();


                //条码拆分
                tmSplit(tm);
            }


        }
    });

    //保存
    function save() {
        //取发货单号
        // var consignment = $("#consignment").val();
        //箱号
        var boxnum = $("#boxnum").val();

        //发货单必输校验
        // if (consignment == "" || consignment == null || consignment == undefined) {
        //     api.toast({
        //         msg: '请扫描/录入发货单！',
        //         duration: 3000
        //     });
        //     return;
        // }

        //箱号必输校验
        if (array == "" || array == null || array == undefined) {
            api.toast({
                msg: '请扫描箱号！',
                duration: 3000
            });
            return;
        }

        //仓库必输校验
        if (workCenterGid == "" || workCenterGid == null || workCenterGid == undefined) {
            api.toast({
                msg: '请选择/扫描 仓库！',
                duration: 3000
            });
            return;
        }

        //库位必输校验
        if (workCellGid == "" || workCellGid == null || workCellGid == undefined) {
            api.toast({
                msg: '请选择/扫描 库位！',
                duration: 3000
            });
            return;
        }
        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/insertStockBox_anChuang";
        var data = {
            values: {
                //                consignment: consignment, //发货单号
                boxnums: array, //箱号数组
                workCenterGid: workCenterGid, //仓库GID
                workCellGid: workCellGid, //库位GID
                un: un
            }
        };

        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == "0") {
                    array = new Array();
                    delArray = new Array();
                    html = "";
                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });
                    //清空表单数据
                    $("#boxnum").val("");
                    $("#boxnum").focus();
                    idSelector = "boxnum";
                    //表格数据赋值
                    var map = myobj.data;
                    for (var key in map) {
                        if (key == "inBillCodeT") {
                            $("#" + key).html(map[key]);
                        }
                        if (key == "workCenterNameT") {
                            $("#" + key).html(map[key]);
                        }
                        if (key == "workCellNameT") {
                            $("#" + key).html(map[key]);
                        }
                        if (key == "createIdT") {
                            $("#" + key).html(map[key]);
                        }
                        if (key == "createDateT") {
                            $("#" + key).html(map[key]);
                        }
                    }

                    //清空div表格数据
                    $api.html($api.byId("tbodyHtml"), html);

                    $("#tableDiv").css('display', 'block');
                    $("#message").val("");

                    //失败
                } else if (myobj.code == "1") {
                    // $("#boxnum").val("");
                    $("#boxnum").val("");
                    $("#boxnum").select();
                    idSelector = "boxnum";
                    api.hideProgress();
                    //$("#boxnum").select();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                $("#boxnum").val("");
                $("#boxnum").select();
                idSelector = "boxnum";
                api.hideProgress();
                //alert(JSON.stringify(err));
                alert("连接超时，请耐心等待");
            }
        });
    }

    //扫完箱号自动保存
    function saveAuto() {

        //取发货单号
        //     var consignment = $("#consignment").val();
        //箱号
        var boxnum = $("#boxnum").val();

        //发货单必输校验
        // if (consignment == "" || consignment == null || consignment == undefined) {
        //     return;
        // }

        //箱号必输校验
        if (boxnum == "" || boxnum == null || boxnum == undefined) {
            return;
        }

        //仓库必输校验
        if (workCenterGid == "" || workCenterGid == null || workCenterGid == undefined) {
            return;
        }

        //库位必输校验
        if (workCellGid == "" || workCellGid == null || workCellGid == undefined) {
            return;
        }

        //保存
        save();
    }

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {

            //1：发货单号
            // if (idSelector == 'consignment') {
            //     $("#consignment").blur();

            //     //发货单号
            //     $("#consignment").val(ret);
            //     // $("#workCenterCode").focus();
            //     // idSelector = "workCenterCode";

            //     //2:箱号
            // } else 
            if (idSelector == 'boxnum') {
                $("#boxnum").blur();
                tmSplit(ret);

                //1：仓库
            } else if (idSelector == 'workCenterCode') {

                $("#workCenterCode").val(ret);
                //查询仓库
                getWorkCenter(ret, idSelector);

                //2:库位
            } else if (idSelector == 'workCellCode') {

                $("#workCellCode").val(ret);
                //查询库位
                getWorkCell(ret, idSelector);

            }
        });
    }

    //扫描之后条码解析
    function tmSplit(sm) {
        $("#tm").val(sm);
        //直接解析
        if (scanRule == "old") {

            //本地解析
            localAnalyze(sm);
            $("#boxnum").val("");

        } else {

            //后台解析
            postAnalyze(sm);
            $("#boxnum").val("");

        }
    }

    //本地解析
    function localAnalyze(sm) {
        var arr = sm.split(",");

        var boxnum = "";
        var mrlCode = "";
        var lotCode = "";
        var qty = "";

        if (arr[1] == null || arr[1] == undefined) {
            mrlCode = "";
        } else {
            mrlCode = (arr[1]);
        }
        if (arr[2] == null || arr[2] == undefined) {
            qty = "";
        } else {
            qty = (arr[2]);
        }
        if (arr[3] == null || arr[3] == undefined) {
            lotCode = "";
        } else {
            lotCode = (arr[3]);
        }
        if (arr[9] == null || arr[9] == undefined) {
            boxnum = "";
        } else {
            boxnum = (arr[9]);
        }
        if (array.includes(boxnum)) {
            $("#boxnum").val("");
            // $("#tm").val("");
            $("#boxnum").select();
            api.toast({
                msg: "箱码已经扫描!",
                duration: 3000
            });
            return;
        }
        if (flag) {
            getWmstockmrlcellrel(mrlCode)
        }

        //    tbodyHtml1+="<tr><td  id='tmID'>"+tmID+"</td></tr>";
        if (!delArray.includes(boxnum)) {
            array.push(boxnum);
            html += "<div id = '" + boxnum + "' class='aaui-btn-info aui-btn-block' style='margin-bottom: 10px;color: black !important;background-color: #addbef !important;height: 110px;padding: 0.2rem 0.2rem;font-size: 0.7rem;'>";
            html += "<table style='width:100%;'>";
            html += "<tr style='width:100%;'><td style='width:16%;'>箱号：</td><td  id='boxnumInfo' style='width:70%;' colspan='2'>" + boxnum + "</td><td><button style = 'background-color:red;color:white' onclick = del('" + boxnum + "')>删除箱</button></td></tr>";
            html += "<tr style='width:100%;'><td style='width:20%;'>物料号：</td> <td  id='mrlCodeInfo' style='width:70%;' colspan='3'>" + mrlCode + "</td></tr>";
            html += "<tr style='width:100%;'><td style='width:20%;'>批次号：</td><td id='lotCodeInfo' style='width:40%;' >" + lotCode + "</td> ";
            html += "<td style='width:16%;'>数量：</td><td id='qtyInfo' style='width:20%;'>" + qty + "</td>";
            html += "</tr>";
            html += "</table></div>";

            $("#tableDiv").css('display', 'none');
            // console.log(html)
            $api.html($api.byId("tbodyHtml"), html);

            for (var k = 0; k < delArray.length; k++) {
                var divToDelete = document.getElementById(delArray[k]);
                divToDelete.parentNode.removeChild(divToDelete);
            }

            // $("#tm").val("");
            $("#boxnum").select();

        }
    }

    //后台解析条码
    function postAnalyze(sm) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/analysisBarCodeCommon";
        var data = {
            values: {
                tm: sm, //条码
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {

                    var map = myobj.data;

                    var boxnum = "";
                    var mrlCode = "";
                    var lotCode = "";
                    var qty = "";
                    // var tmID = "";
                    for (var key in map) {
                        // $("#" + key).val(map[key]);



                        if ("boxnum" == key) {
                            boxnum = map[key];
                        }
                        if ("mrlCode" == key) {
                            mrlCode = map[key];
                        }
                        if ("lotCode" == key) {
                            lotCode = map[key];
                        }
                        if ("qty" == key) {
                            qty = map[key];
                        }
                        if ("qty" == key) {
                            qty = map[key];
                        }
                        // if("tmID" == key){
                        //     tmID=  map[key] ;

                        // }

                        // html=boxnum+mrlCode+"<tr style='text-align: center;background-color: #F5F5F5;color: black;font-size: 8px;>"+lotCode+qty+"</tr>"
                    }
                    if (array.includes(boxnum)) {
                        $("#boxnum").val("");
                        // $("#tm").val("");
                        $("#boxnum").select();
                        api.toast({
                            msg: "箱码已经扫描!",
                            duration: 3000
                        });
                        return;
                    }
                    if (flag) {
                        getWmstockmrlcellrel(mrlCode)
                    }

                    //    tbodyHtml1+="<tr><td  id='tmID'>"+tmID+"</td></tr>";
                    if (!delArray.includes(boxnum)) {
                        array.push(boxnum);
                        html += "<div id = '" + boxnum + "' class='aaui-btn-info aui-btn-block' style='margin-bottom: 10px;color: black !important;background-color: #addbef !important;height: 110px;padding: 0.2rem 0.2rem;font-size: 0.7rem;'>";
                        html += "<table style='width:100%;'>";
                        html += "<tr style='width:100%;'><td style='width:16%;'>箱号：</td><td  id='boxnumInfo' style='width:70%;' colspan='2'>" + boxnum + "</td><td><button style = 'background-color:red;color:white' onclick = del('" + boxnum + "')>删除箱</button></td></tr>";
                        html += "<tr style='width:100%;'><td style='width:20%;'>物料号：</td> <td  id='mrlCodeInfo' style='width:70%;' colspan='3'>" + mrlCode + "</td></tr>";
                        html += "<tr style='width:100%;'><td style='width:20%;'>批次号：</td><td id='lotCodeInfo' style='width:40%;' >" + lotCode + "</td> ";
                        html += "<td style='width:16%;'>数量：</td><td id='qtyInfo' style='width:20%;'>" + qty + "</td>";
                        html += "</tr>";
                        html += "</table></div>";

                        $("#tableDiv").css('display', 'none');
                        // console.log(html)
                        $api.html($api.byId("tbodyHtml"), html);

                        for (var k = 0; k < delArray.length; k++) {
                            var divToDelete = document.getElementById(delArray[k]);
                            divToDelete.parentNode.removeChild(divToDelete);
                        }

                        // $("#tm").val("");
                        $("#boxnum").select();

                    }

                    // else{
                    //     $("#boxnum").val("");
                    //     // $("#tm").val("");
                    //     $("#boxnum").select();
                    //     api.toast({
                    //         msg: "删除掉的箱不允许当前收货单继续扫码收货!",
                    //         duration: 3000
                    //     });
                    //     return;
                    //}

                    // $api.html($api.byId("tbodyHtml1"), tbodyHtml1);

                    // $("#boxTable").append("<tr><td>箱号:</td>"+boxnum+"<td>物料号:</td>"+mrlCode+"</tr>"+"<tr><td>批次:</td>"+lotCode+"<td>数量:</td>"+qty+"</tr>");  
                    //自动入库
                    // saveAuto();
                } else if (myobj.code == '1') {

                    $("#boxnum").val("");
                    // $("#tm").val("");
                    $("#boxnum").select();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                //alert(JSON.stringify(err));
                alert("连接超时，请耐心等待");
            }
        });
    }

    //查询库位物料关系
    function getWmstockmrlcellrel(mrlCode) {
        var distributeTaskCode = $("#distributeTaskCode").val();
        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWmstockmrlcellrel";
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';
        var data = {
            values: {
                mrlCode: mrlCode,//物料
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            flag = false;
            if (ret) {

                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    api.hideProgress();
                    $("#message").val(myobj.message);
                } else {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            }
        });

    }

    function del(boxnum) {
        delArray.push(boxnum);
        array = array.filter(function (item) { return item != boxnum });
        //console.log(boxnum)
        var divToDelete = document.getElementById(boxnum);
        divToDelete.parentNode.removeChild(divToDelete);
        //  $("#"+boxnum).remove();
        //  $("#"+boxnum).html("");
        //  document.getElementById(boxnum).remove();
        //document.getElementById(boxnum).innerHTML="";
        // document.getElementById("#"+boxnum).remove();

    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>